﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OnlineShop.Common;
using OnlineShop.Models;
using PaymentHelper;
using PaymentHelper.Core.RelatedObject;
using OnlineShop.Models.ViewModels;
using System.Web.Routing;
using PaymentHelper.Core;
using PaymentHelper.PaymentFlow;

namespace OnlineShop.Controllers
{
    public class PaymentController : BaseController
    {
        #region Repository
        private IOnlineShopRepository repository;

        public PaymentController():this(new EFOnlineShopRepository())
        {
        }

        public PaymentController(EFOnlineShopRepository eFOnlineShopRepository)
        {
            this.repository = eFOnlineShopRepository;
        }

        #endregion

        private BasePaymentFlow _paymentFlow;

        //
        // GET: /Payment/

        public ActionResult Index()
        {
            if (CurrentUser == null)
                return RedirectToLogin();

            //Set order handler
            PaymentFlowManager.OrderHandler = new MyOrderHandler();

            _paymentFlow = PaymentFlowManager.LoadDefaultPaymentFlow();

            _paymentFlow.InitializeOrderPayment();

            var firstStepRoute = _paymentFlow.GetFirstStepRoute();

            return RedirectToRoute(firstStepRoute.RouteName);

        }
    }
}
